package com.content.scaffold.common.utils;

import com.content.scaffold.common.annotation.SensitiveField;
import com.content.scaffold.model.dto.sys.QueryUserPage;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;

import java.lang.reflect.Field;

public class TestUtil {

    public static void printSensitiveFields(Class<?> clazz) {
        while (clazz != null && clazz != Object.class) {
            for (Field field : clazz.getDeclaredFields()) {
                SensitiveField annotation = field.getAnnotation(SensitiveField.class);
                System.out.printf("Class: %s, Field: %s, Has SensitiveField: %s%n",
                        clazz.getSimpleName(),
                        field.getName(),
                        annotation != null);
            }
            clazz = clazz.getSuperclass();
        }
    }

    public static void main(String[] args) {
        printSensitiveFields(QueryUserPage.class);
    }

    public static Class<?> resolveRealClass(Object obj) {
        if (AopUtils.isAopProxy(obj)) {
            return AopProxyUtils.ultimateTargetClass(obj);
        }
        return obj.getClass();
    }

}
